package addBinary;

public class Solution {
    public static void main(String[] args) {
        System.out.println(addBinary("11111","11111"));
    }
    public static String addBinary(String a, String b) {
        int i=a.length()-1;
        int j=b.length()-1;
        int t=0;
        StringBuilder sb=new StringBuilder();
        while(i>=0||j>=0||t!=0){
            int sum=t;
            if(i>=0){
                int value=a.charAt(i)-'0';
                sum+=value;
                --i;
            }
            if(j>=0){
                int value=b.charAt(j)-'0';
                sum+=value;
                --j;
            }
            char c=(char) (sum%2+'0');
            t=sum/2;
            sb.append(c);
        }
        return sb.reverse().toString();
    }
}
// 11111
// 11111
//       0011101  1011100